import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Factory {
    public static void main(String[] args) {
//        BigDecimal number = new BigDecimal(96.576575675757575751);
//        //.setScale(4,BigDecimal.ROUND_HALF_DOWN)
////        number.setScale(1,BigDecimal.ROUND_DOWN); //直接删除多余的小数位，如2.35会变成2.3
//        BigDecimal number1 = new BigDecimal(String.valueOf(number)).setScale(5,BigDecimal.ROUND_HALF_DOWN);
//
//        System.out.println(number1.toString());

        List<BizContractFormDTO> formContentList =new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            BizContractFormDTO bizContractFormDTO = new BizContractFormDTO();
            bizContractFormDTO.setBrandMaterial("2222");
            bizContractFormDTO.setContractId("2222");
            bizContractFormDTO.setNumber(new BigDecimal(0.22222233333333333));
            bizContractFormDTO.setPrice(new BigDecimal(0.111111133333333333333));
            formContentList.add(bizContractFormDTO);
        }

        List<String> calculate = calculate(formContentList);
        System.out.println(calculate.get(0)+"  "+calculate.get(1));
    }

    private static List<String> calculate(List<BizContractFormDTO> formContentList) {

        BigDecimal number = new BigDecimal(0);
        BigDecimal totalPrice = new BigDecimal(0);
        List<String> list = new ArrayList<>();
        for (BizContractFormDTO bizContractFormDTO : formContentList) {
            number = number.add(Objects.isNull(bizContractFormDTO.getNumber()) ?
                    BigDecimal.ZERO :
                    bizContractFormDTO.getNumber());
            totalPrice = totalPrice.add(Objects.isNull(bizContractFormDTO.getTotalPrice()) ?
                    BigDecimal.ZERO :
                    bizContractFormDTO.getTotalPrice());
        }
        BigDecimal number1 = new BigDecimal(String.valueOf(number)).setScale(4,BigDecimal.ROUND_HALF_DOWN);
        BigDecimal totalPrice1 = new BigDecimal(String.valueOf(number)).setScale(2,BigDecimal.ROUND_HALF_DOWN);

        list.add(number1.toString());
        list.add(totalPrice1.toString());
        return list;
    }
}
